package com.example.cr.insect.controller.admin;

import com.example.cr.common.response.PageResponse;
import com.example.cr.common.response.R;
import com.example.cr.insect.request.LocationListRequest;
import com.example.cr.insect.response.LocationResponse;
import com.example.cr.insect.service.LocationService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.cr.insect.request.LocationRequest;
import java.util.List;

@RestController
@RequestMapping("admin/location")
public class LocationAdminController {
    @Autowired
    LocationService locationService;

    @GetMapping("list")
    public R<PageResponse<LocationResponse>> list(@Valid LocationListRequest request) {
        PageResponse<LocationResponse> list = locationService.list(request);
        return R.ok(list);
    }
    @PostMapping("save")
    public R<Object> save(@Valid @RequestBody LocationRequest request) {
        locationService.save(request);
        return R.ok();
    }

    @DeleteMapping("delete")
    public R<Integer> delete(@RequestBody List<Long> ids) {
        int result = locationService.deleteBatch(ids);
        return R.ok(result);
    }
}
